/*
* coder: Dzlua
* email: 505544956@qq.com
* time : 2018-04-13 15:55
*/
#pragma once
#ifndef __UTILS_HPP__
#define __UTILS_HPP__

UI_BEGIN_NAMESPACE

/*
* for class map functions.
*/
#define UI_CLASS_MAP_FUNS(T, V, name) \
    protected: \
        CMap<T, V> map_##name##_; \
    public: \
        CMap<T, V>& Get##name##Map() { return map_##name##_; } \
        void Add##name(const T& key, CMap<T, V>::TELE_INFO& wnd) { map_##name##_.insert(key, wnd); } \
        CMap<T, V>::TELE_INFO Get##name(const T& key) { \
            auto itor = map_##name##_.find(key); \
            if (itor == map_##name##_.end()) return nullptr; \
            return itor->second; \
        } \
        void Remove##name(const T& key) { map_##name##_.erase(key); } \
        void Remove##name(CMap<T, V>::TELE_INFO& wnd) { map_##name##_.erase(wnd); } \
        void Clear##name() { map_##name##_.clear(); }
#define UI_CLASS_SIMPLE_MAP_FUNS(T, V, name) \
    protected: \
        CSimpleMap<T, V> map_##name##_; \
    public: \
        CSimpleMap<T, V>& Get##name##Map() { return map_##name##_; } \
        void Add##name(const T& key, CSimpleMap<T, V>::TELE_INFO& wnd) { map_##name##_.insert(key, wnd); } \
        CSimpleMap<T, V>::TELE_INFO Get##name(const T& key) { \
            auto itor = map_##name##_.find(key); \
            if (itor == map_##name##_.end()) return nullptr; \
            return itor->second; \
        } \
        void Remove##name(const T& key) { map_##name##_.erase(key); } \
        void Remove##name(CSimpleMap<T, V>::TELE_INFO& wnd) { map_##name##_.erase(wnd); } \
        void Clear##name() { map_##name##_.clear(); }

/*
* for class array functions.
*/
#define UI_CLASS_ARRAY_FUNS(V, name) \
    protected: \
        CArray<V> array_##name##_; \
    public: \
        CArray<V>& Get##name##Array() { return array_##name##_; } \
        void Add##name(CArray<V>::TELE_INFO& ele) { array_##name##_.add(ele); } \
        void Remove##name(CArray<V>::TELE_INFO& ele) { array_##name##_.erase(ele); } \
        void Clear##name() { array_##name##_.clear(); }
#define UI_CLASS_SIMPLE_ARRAY_FUNS(V, name) \
    protected: \
        CSimpleArray<V> array_##name##_; \
    public: \
        CSimpleArray<V>& Get##name##Array() { return array_##name##_; } \
        void Add##name(CSimpleArray<V>::TELE_INFO& ele) { array_##name##_.add(ele); } \
        void Clear##name() { array_##name##_.clear(); }

/*
* for class set/get functions.
*/
#define UI_CLASS_SETGET_FUNS(V, name) \
    protected: \
        V sg_##name##_; \
    public: \
        V Get##name() { return sg_##name##_; } \
        void Set##name(V& ele) { sg_##name##_ = ele; }
#define UI_CLASS_SETGET_VIRTUAL_FUNS(V, name) \
    protected: \
        V sg_##name##_; \
    public: \
        virtual V Get##name() { return sg_##name##_; } \
        virtual void Set##name(V& ele) { sg_##name##_ = ele; }
#define UI_CLASS_SETGET_INIT(name, value) sg_##name##_(value)

UI_END_NAMESPACE

#endif
